package cn.hpclub.server.model;

import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

import com.jfinal.ext.plugin.tablebind.TableBind;
import com.jfinal.plugin.activerecord.Model;

@TableBind(tableName="brand")
public class Brand extends Model<Brand> {
	private static final long serialVersionUID = 2481687865516887379L;
	public static final Brand dao              = new Brand();
	
	public static String ID                    = "id";         //品牌主键
	public static String NAME                  = "name";       //品牌名称
	public static String CREATE_TIME           = "create_time";//品牌主键创建时间
	
	public String getSelect() {
		String select = " select * ";
        return select;
	}
	public String getSqlExceptSelect(ConcurrentHashMap<String, String> searchInfo) {
		String sqlExceptSelect = " from brand b where 1=1";

        for(Entry<String, String> item : searchInfo.entrySet()){
            sqlExceptSelect += buildQuery(item);
        }
        return sqlExceptSelect;
	}
	private String buildQuery(Entry<String, String> item) {
		String sql = "";
        if(item.getKey().equals("name")){
            sql += " and b.name like '%" + item.getValue() + "%' ";
        } else if(item.getKey().equals("starttime")){
            sql += " and b.create_time >='" + item.getValue()+"'";// + " 00:00:00" + "' ";
        }else {
			sql += " and b.create_time <='" + item.getValue()+"'";// + " 23:59:59" + "' ";
		}

        return sql;
	}
}